package table.view;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Point;

import javax.swing.Icon;

import table.model.rowModel.ColumnDirection;

public class Arrow implements Icon {
    private int arrowState;
    private int size;

    public Arrow(int arrowState) {
        this.arrowState = arrowState;
    }
    
	public void paintIcon(Component c, Graphics g, int x, int y) {
		if(arrowState == ColumnDirection.NOT_SORTED) {
			return;
		}
        Color color = Color.BLACK;
		
		
		//draw center line
        Point topPoint = new Point(x + size/4, y + size/6);
        Point bottomPoint = new Point(x + size/4, y + 5* size/6);
		g.setColor(color);
		g.drawLine(topPoint.x, topPoint.y, bottomPoint.x, bottomPoint.y);
		
		switch(arrowState) {
			case ColumnDirection.ASCENDING: {
				g.drawLine(x + size/8, y + 4*size/6, bottomPoint.x, bottomPoint.y);
				g.drawLine(x + 3*size/8, y + 4*size/6, bottomPoint.x, bottomPoint.y);
				break;
			}
			case ColumnDirection.DESCENDING: {
				g.drawLine(x + size/8, y + size/3, topPoint.x, topPoint.y);
				g.drawLine(x + 3*size/8, y + size/3, topPoint.x, topPoint.y);
				break;
			}
		}
	}

	public void setSize(int size) {
		this.size = size;
	}
	
	public int getIconWidth() {
		return size/2;
	}

	public int getIconHeight() {
		return size;
	}

	public void setDirection(int direction) {
		arrowState = direction;
	}
}
